package com.nasarius.bank.scorecard.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.nasarius.bank.scorecard.dao.BankFactorsActualDAO;
import com.nasarius.bank.scorecard.domain.BankFactorsActual;
import com.nasarius.bank.scorecard.domain.BankFactorsActualExample;
@Repository
public class BankFactorsActualDAOImpl extends SqlMapClientDaoSupport implements BankFactorsActualDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
	@Autowired
    public BankFactorsActualDAOImpl(/*@Qualifier("sqlMapClient")*/SqlMapClient sqlMapClient) {
        super();
        setSqlMapClient(sqlMapClient);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public int countBankFactorsActualByExample(BankFactorsActualExample example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("bank_factors_actual.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public int deleteBankFactorsActualByExample(BankFactorsActualExample example) {
        int rows = getSqlMapClientTemplate().delete("bank_factors_actual.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public void insertBankFactorsActual(BankFactorsActual record) {
        getSqlMapClientTemplate().insert("bank_factors_actual.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public void insertBankFactorsActualSelective(BankFactorsActual record) {
        getSqlMapClientTemplate().insert("bank_factors_actual.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    @SuppressWarnings("unchecked")
    public List<BankFactorsActual> selectBankFactorsActualByExample(BankFactorsActualExample example) {
        List<BankFactorsActual> list = getSqlMapClientTemplate().queryForList("bank_factors_actual.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public int updateBankFactorsActualByExampleSelective(BankFactorsActual record, BankFactorsActualExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("bank_factors_actual.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    public int updateBankFactorsActualByExample(BankFactorsActual record, BankFactorsActualExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("bank_factors_actual.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table bank_factors_actual
     *
     * @ibatorgenerated Mon Mar 21 00:15:27 IST 2011
     */
    private static class UpdateByExampleParms extends BankFactorsActualExample {
        private Object record;

        public UpdateByExampleParms(Object record, BankFactorsActualExample example) {
            super(example);
            this.record = record;
        }

        @SuppressWarnings("unused")
		public Object getRecord() {
            return record;
        }
    }

	

	@SuppressWarnings("unchecked")
	@Override
	public List<BankFactorsActual> bankFactorsActualByBankCode(List<String> bankCodes,
			Date fromDt, Date toDt) {
		Map<String,Object> criteria= new HashMap<String,Object>();   
		criteria.put("bankCodeList",bankCodes);
		criteria.put("fromdt",fromDt);
		criteria.put("todt",toDt);
		List<BankFactorsActual> list =(List<BankFactorsActual>) getSqlMapClientTemplate().queryForList("bank_factors_actual.bankFactorsActualByBankCode", criteria);
	    return list;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<BankFactorsActual> factorsForGraph(List<String> bankCodes,List<String> factorIDs,
			Date fromDt, Date toDt) {
		Map<String,Object> criteria= new HashMap<String,Object>();   
		criteria.put("bankCodeList",bankCodes);
		criteria.put("factorIDList",factorIDs);		
		criteria.put("fromdt",fromDt);
		criteria.put("todt",toDt);
		List<BankFactorsActual> list =(List<BankFactorsActual>) getSqlMapClientTemplate().queryForList("bank_factors_actual.bankFactorsForGraph", criteria);
		return list;
	}
	@SuppressWarnings("unchecked")
	@Override
	public Integer bankFactorsActualByFactor(String bankcode, String factorId,
			Date fromDt, Date toDt) {
		BankFactorsActual key = new BankFactorsActual();
		key.setBankcode(bankcode);
		key.setFactorid(Integer.valueOf(factorId));
		key.setFromdt(fromDt);
		key.setTodt(toDt);
		List<BankFactorsActual> list =(List<BankFactorsActual>) getSqlMapClientTemplate().queryForList("bank_factors_actual.bankFactorsActualByFactor", key);
		Integer actualValue=0;
		for(BankFactorsActual bankFactorsActual:list){
			if (bankFactorsActual.getActualvalue() != null && bankFactorsActual.getActualvalue() > 0){
				actualValue=bankFactorsActual.getActualvalue();
			}				
		}
	    return actualValue;
	}
	   /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table bank_factors
     *
     * @ibatorgenerated Mon Mar 21 00:22:54 IST 2011
     */
    public int deleteBankFactorsByFactorID(Integer factorid) {
    	BankFactorsActual key = new BankFactorsActual();
        key.setFactorid(factorid);
        int rows = getSqlMapClientTemplate().delete("bank_factors_actual.ibatorgenerated_deleteByFactorID", key);
        return rows;
    }
	@SuppressWarnings("unchecked")
	@Override
	public List<BankFactorsActual> factorsForFactorAnalysis(Date fromDt, Date toDt) {
		Map<String,Object> criteria= new HashMap<String,Object>();   	
		criteria.put("fromdt",fromDt);
		criteria.put("todt",toDt);
		List<BankFactorsActual> list =(List<BankFactorsActual>) getSqlMapClientTemplate().queryForList("bank_factors_actual.bankFactorsForFactorAnalysis", criteria);
		return list;
	}    
}